<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="业主名称" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:owner:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:owner:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:owner:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:owner:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ownerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="收房合同id" align="center" prop="contractId" />
      <el-table-column label="名称" align="center" prop="ownerName" />
      <el-table-column label="证件类型" align="center" prop="certificateType" />
      <el-table-column label="身份证" align="center" prop="idCard" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="联系人地址" align="center" prop="address" />
      <el-table-column label="紧急联系人电话" align="center" prop="urgMobile" />
      <el-table-column label="银行卡号" align="center" prop="bankCard" />
      <el-table-column label="持卡人姓名" align="center" prop="bankUserName" />
      <el-table-column label="持卡人身份证" align="center" prop="bankUserIdCard" />
      <el-table-column label="银行ID" align="center" prop="bankId" />
      <el-table-column label="银行名称" align="center" prop="bankName" />
      <el-table-column label="开户银行(支行)" align="center" prop="bankOpen" />
      <el-table-column label="银行账户类型" align="center" prop="accountType" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber" />
      <el-table-column label="账户名称" align="center" prop="accountName" />
      <el-table-column label="联行行号" align="center" prop="bankBranchCodeLh" />
      <el-table-column label="开户行所在省ID" align="center" prop="bankAccountProvince" />
      <el-table-column label="预留字段1" align="center" prop="reserve1" />
      <el-table-column label="预留字段2" align="center" prop="reserve2" />
      <el-table-column label="预留字段3" align="center" prop="reserve3" />
      <el-table-column label="预留字段4" align="center" prop="reserve4" />
      <el-table-column label="预留字段5" align="center" prop="reserve5" />
      <el-table-column label="删除标识：0： 未删除， 1：删除" align="center" prop="delFlg" />
      <el-table-column label="创建用户" align="center" prop="createUserid" />
      <el-table-column label="更新用户id" align="center" prop="updateUserid" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:owner:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:owner:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="收房合同id" prop="contractId">
          <el-input v-model="form.contractId" placeholder="请输入收房合同id" />
        </el-form-item>
        <el-form-item label="名称" prop="ownerName">
          <el-input v-model="form.ownerName" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="证件类型" prop="certificateType">
          <el-select v-model="form.certificateType" placeholder="请选择证件类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="身份证" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="联系人地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入联系人地址" />
        </el-form-item>
        <el-form-item label="紧急联系人电话" prop="urgMobile">
          <el-input v-model="form.urgMobile" placeholder="请输入紧急联系人电话" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCard">
          <el-input v-model="form.bankCard" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="持卡人姓名" prop="bankUserName">
          <el-input v-model="form.bankUserName" placeholder="请输入持卡人姓名" />
        </el-form-item>
        <el-form-item label="持卡人身份证" prop="bankUserIdCard">
          <el-input v-model="form.bankUserIdCard" placeholder="请输入持卡人身份证" />
        </el-form-item>
        <el-form-item label="银行ID" prop="bankId">
          <el-input v-model="form.bankId" placeholder="请输入银行ID" />
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称" />
        </el-form-item>
        <el-form-item label="开户银行(支行)" prop="bankOpen">
          <el-input v-model="form.bankOpen" placeholder="请输入开户银行(支行)" />
        </el-form-item>
        <el-form-item label="银行账户类型" prop="accountType">
          <el-select v-model="form.accountType" placeholder="请选择银行账户类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="账户名称" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户名称" />
        </el-form-item>
        <el-form-item label="联行行号" prop="bankBranchCodeLh">
          <el-input v-model="form.bankBranchCodeLh" placeholder="请输入联行行号" />
        </el-form-item>
        <el-form-item label="开户行所在省ID" prop="bankAccountProvince">
          <el-input v-model="form.bankAccountProvince" placeholder="请输入开户行所在省ID" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识：0： 未删除， 1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识：0： 未删除， 1：删除" />
        </el-form-item>
        <el-form-item label="创建用户" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户" />
        </el-form-item>
        <el-form-item label="更新用户id" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOwner, getOwner, delOwner, addOwner, updateOwner } from "@/api/contract/owner";

export default {
  name: "index",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      ownerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractId: null,
        ownerName: null,
        certificateType: null,
        idCard: null,
        mobile: null,
        address: null,
        urgMobile: null,
        bankCard: null,
        bankUserName: null,
        bankUserIdCard: null,
        bankId: null,
        bankName: null,
        bankOpen: null,
        accountType: null,
        bankCardNumber: null,
        accountName: null,
        bankBranchCodeLh: null,
        bankAccountProvince: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ownerName: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识：0： 未删除， 1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户id不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listOwner(this.queryParams).then(response => {
        this.ownerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractId: null,
        ownerName: null,
        certificateType: null,
        idCard: null,
        mobile: null,
        address: null,
        urgMobile: null,
        bankCard: null,
        bankUserName: null,
        bankUserIdCard: null,
        bankId: null,
        bankName: null,
        bankOpen: null,
        accountType: null,
        bankCardNumber: null,
        accountName: null,
        bankBranchCodeLh: null,
        bankAccountProvince: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOwner(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOwner(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOwner(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOwner(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/owner/export', {
        ...this.queryParams
      }, `system_owner.xlsx`)
    }
  }
};
</script>
